/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package controller;

import core.ProcessOwnerCore;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import model.Costumer;
import model.Dapstructure;
import model.Stepvalidation;

/**
 *
 * @author phinguyen
 */
public class Servletcustomerselecedindicator extends HttpServlet {

  
    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
          String iddaps=request.getParameter("iddap");
        String idcos=request.getParameter("idcos");
        System.out.println("iddapscustomer---------------------------------------------------------------------"+idcos);
        int iddap=Integer.parseInt(iddaps);
//        int idc=Integer.parseInt(idcos);
        ProcessOwnerCore po=new ProcessOwnerCore();
         Dapstructure daps=po.getDAPstructureid(iddap);
         Costumer cos=po.getCostumerByname(idcos);
         System.out.println("dapscustomer---------------------------------------------------------------------"+cos);
        HashMap<Integer, Stepvalidation> mapStep=po.getDapStep(daps);
        response.setContentType("application/xml");
        PrintWriter out = response.getWriter();
        out.println("<?xml version=\"1.0\"?>");
        out.println("<list_steps>");
        for (Map.Entry<Integer, Stepvalidation> entry : mapStep.entrySet()) {
            out.println("<ordre>"+entry.getKey()+"</ordre>"); 
            out.println("<step>"+entry.getValue().getSvname()+"</step>");
            out.println("<nbvalidate>"+po.getnbDesicionvalidate(daps, entry.getValue())+"</nbvalidate>");
            out.println("<percentagevalidate>"+po.pourcentagedecision(daps, entry.getValue())+"</percentagevalidate>");
            out.println("<nbvalidatecostumer>"+po.getNbValidationsByCustomer(cos,daps, entry.getValue())+"</nbvalidatecostumer>");
            out.println("<percentagevalidatecostumer>"+po.pourcentagedecisionCustomer(cos,daps, entry.getValue())+"</percentagevalidatecostumer>");
        }
        out.println("</list_steps>");
    }

    /**
     * Handles the HTTP <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doGet(request, response);
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>

}
